﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

namespace E2_WEBSITE.Code
{
    public static class Utilities
    {
        public const string DateTimeFormatString = "M/d/yyyy h:m:s tt";
        public const string DefaultPassword = "123456";
        public const string ErrorPagePath = "~/Common/Error.aspx";

        public static string ConvertToMoneyFormat(int iMoney,bool bIsVND)
        {
            if (bIsVND)
            {
                string s = iMoney.ToString("N", CultureInfo.CreateSpecificCulture("en-US"));
                int iIndex = s.LastIndexOf(".");
                s = s.Substring(0, iIndex);
                s += " VND";
                return s.Replace(",",".");
            }
            else
                return iMoney.ToString("C", CultureInfo.CreateSpecificCulture("en-US"));
        }

        public static int ParseVNDMoneyFormatToValue(string sMoney)
        {
            int iValue;
            sMoney = sMoney.Replace(" VND", "");
            sMoney = sMoney.Replace(".", "");
            if (int.TryParse(sMoney, out iValue))
            {
                return iValue;
            }
            else
                return 0;
        }

        public static int ConvertVNDToUSD(int iVNDMoney,int iVNDPerUSD)
        {
            return iVNDMoney / iVNDPerUSD;
        }

        public static int ConvertUSDToVND(int iUSDMoney,int iVNDPerUSD)
        {
            return iUSDMoney * iVNDPerUSD;
        }

        public static string ConvertToMoneyFormat(int iMoney)
        {
            string s = iMoney.ToString();
            int i;
            for (i = s.Length - 3; i > 0; i -= 3)
            {
                s = s.Insert(i, ".");
            }
            return s;
        }
    }
}
